package com.gitee.wsl.ext.base

import com.gitee.wsl.config.AbstractConfigModel
import com.gitee.wsl.data.store.StoreServer
import com.gitee.wsl.data.store.cache.MemoryStoreServer
import org.junit.Test


import java.util.TreeSet

class ConfigModelTest {

    val example= Example(false)

    @Test
     fun testConfigModel(){

        example.testFloat=0.1f

        println("float:${example.testFloat}")

        println("boolean:${example.testBoolean}")
     }


    @Test
    fun addAndRemoveStringSetPrefItemsCausePreferenceUpdate() {
        example.testStringSet.apply {
            add("test1")
            add("test2")
            add("test3")
            remove("test2")
            add("test4")
        }

        println("stringSet:${example.testStringSet}")
    }

    /*@Test
    fun testPrefConfigModel(){
        val config=ConfigFactory.parseString("""
            # these are our own config values defined by the app
            complex-app {
                something="This value comes from complex-app's complex1.conf"
            }

            # Here we override some values used by a library
            simple-lib.foo="This value comes from complex-app's complex1.conf"
            simple-lib.whatever = "This value comes from complex-app's complex1.conf"
            
            testFloat=16
        """.trimIndent())
        val configStoreServer= com.gitee.wsl.store.config.ConfigStoreServer(config)
        val example= Example(false,configStoreServer)


        println("float:${example.testFloat}")

        println("boolean:${example.testBoolean}")

        println("get config value complex-app.something:${config.getString("complex-app.something")}")

    }*/

}


class Example(private val commitAllProperties: Boolean,storeServer: StoreServer = MemoryStoreServer.defaultServer) : AbstractConfigModel(storeServer) {
    override val commitAllPropertiesByDefault: Boolean
        get() = commitAllProperties

    var testInt by intPref()
    var testLong by longPref()
    var testFloat by floatPref()
    var testBoolean by booleanPref()
    var testString by stringPref()
    var testStringNullable by nullableStringPref()
    val testStringSet by stringSetPref(TreeSet())
}
